import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by User on 09.05.14.
 */
public class SalaryManager {
    public List<Deployee> listSalary;
    ManagerDeployee m = new ManagerDeployee();


    private Double salary;


    public double midKTU() {

        listSalary = m.generList();

        Iterator<Deployee> it = listSalary.iterator();
        double count = 0;
        while (it.hasNext()) {
            count += it.next().getKtu();
        }
        return count;
    }
    public static String show(){
        ManagerDeployee md = new ManagerDeployee();
        List<String> listSal = FileMaster.getFileContent(md.getPATH1());
        Iterator<String> it = listSal.iterator();
        String tmp="";
        while (it.hasNext()){
                tmp+= (it.next()+"\n\n");
        }
        return tmp;
    }

    public void persSalary(double salary) {

        listSalary = m.generList();
        List<Deployee> salaryPers = new LinkedList<Deployee>();
        Iterator<Deployee> it = listSalary.iterator();
        Deployee tmp;
        double sp;
        double midSalary = salary / midKTU();
        while (it.hasNext()) {
            tmp = it.next();

            salaryPers.add(new Deployee(tmp.getKtu(), tmp.getName(), tmp.getLocalization(), tmp.setSalary((int) (midSalary*tmp.getKtu()))));
        }
        List<String> inFile = new LinkedList<String>();
        Iterator<Deployee> iter = salaryPers.iterator();
        Deployee dep;
        while (iter.hasNext()) {
            dep = iter.next();
            inFile.add(dep.toString());
        }

                FileMaster.writeToFile(inFile, m.getPATH1());
    }

}
